package com.diipo.weibo;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.Iterator;
import java.util.LinkedList;

import com.diipo.weibo.adapter.DetailsItemAdapter;
import com.diipo.weibo.entity.Comments;
import com.diipo.weibo.entity.Details;
import com.diipo.weibo.entity.HomeAll;
import com.diipo.weibo.utils.HttpUtils;
import com.diipo.weibo.utils.JsonUtils;
import com.diipo.weibo.utils.TimeUtil;
import com.google.gson.reflect.TypeToken;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

public class WeiboDetailsActivity extends Activity {

	// String url_show_root_id = "/api/statuses/show/"+mId+".json?api_key=";
	// /api/stauses/comments.[json]
	// url_all_comments = "/api/statuses/comments.json?api_key=";
	public String url_show_id;
	public String url_show_root_id;
	public String url_all_comments;
	public String mId;
	public String mNofity_id;
	public String mRootId;
	public String mApp_type;
	public String mItemType;
	private String TAG = WeiboDetailsActivity.class.getSimpleName();
	private Details mDetails = new Details();
	private ImageView mIcon;
	private TextView mName;
	private TextView mCreateTime;
	private TextView mAppTypeTimeTitle;
	private TextView mAppTypeTime;
	private TextView mCommentTitle;
	private TextView mCnt;// the number of the comment
	private TextView mAppTypeContent; // details_app_type_content
	private TextView mAppTypeStatus;// the status of the task
	private ImageView mShowHtml;
	private TextView mContent;
	private TextView mLinkContent;
	private ImageView mPicContent;
	private View mDivider;
	private LinearLayoutForListView mDetailsList;
//	private LinearLayout footView;
	private Context mctx;
	private AsyncImageLoader asyncImageLoader = AsyncImageLoader.getInstance();

	private int TASK_UNDONE = 0;
	private int TASK_DONE = 1;

	private int MEETING_INIT = 2;
	private int MEETING_JOIN = 3;
	private int MEETING_UNJOIN = 4;
	private int MEETING_UNKNOW = 5;

	private int EVENT_INIT = 6;
	private int EVENT_JOIN = 7;
	private int EVENT_UNJOIN = 8;
	private int EVENT_UNKNOW = 9;

	private int APPROVE_INIT = 10;
	private int APPROVE_FINAL = 11; // pass or unpass

	private int REPLY_BTN = 12;
	private int MSG_REPLY = 13;

	private Button mbtnBack;
	private Button mbtnReply;
	// private final int REPLY_WEIBO = 11;
	// private final int REPLY_PRIVATE = 12;

	private ImageView mReplyType;
	private Comments[] mArrayComments = new Comments[] {};

	Intent mIntent;
	private TextView mHeaderMore;

	// review the orgin msg,id change to the root_id
	private boolean mFlag = false;

	// get all comments if the comment more than 10
	private boolean mIsLargeTen = false;
	private Type listType = new TypeToken<LinkedList<Comments>>() {
	}.getType();
	private LinkedList<Comments> mCommentsList = new LinkedList<Comments>();
	private Comments[] mArrayAllComments = new Comments[] {};

	private Handler handler = new Handler();

	public class Utility {
		public void setListViewHeightBasedOnChildren(ListView listView) {
			// 获取ListView对应的Adapter
			ListAdapter listAdapter = listView.getAdapter();
			if (listAdapter == null) {
				return;
			}

			int totalHeight = 0;
			for (int i = 0, len = listAdapter.getCount(); i < len; i++) { // listAdapter.getCount()返回数据项的数目
				View listItem = listAdapter.getView(i, null, listView);
				listItem.measure(0, 0); // 计算子项View 的宽高
				totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
			}

			ViewGroup.LayoutParams params = listView.getLayoutParams();
			params.height = totalHeight
					+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
			// listView.getDividerHeight()获取子项间分隔符占用的高度
			// params.height最后得到整个ListView完整显示需要的高度
			listView.setLayoutParams(params);
		}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		// Hide title
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.weibo_details_view);
		mItemType = "";
		mctx = this;
		mIcon = (ImageView) findViewById(R.id.details_view_icon);
		mName = (TextView) findViewById(R.id.details_view_name);
		mCreateTime = (TextView) findViewById(R.id.details_view_createTime);
		mAppTypeTimeTitle = (TextView) findViewById(R.id.details_app_type_time_title);
		mAppTypeTime = (TextView) findViewById(R.id.details_app_type_time);
		mCommentTitle = (TextView) findViewById(R.id.details_view_commentname);
		mCnt = (TextView) findViewById(R.id.details_view_comment_cnt);
		mAppTypeContent = (TextView) findViewById(R.id.details_app_type_content);
		mAppTypeStatus = (TextView) findViewById(R.id.details_app_type_status);

		mReplyType = (ImageView) findViewById(R.id.weibo_item_pw_type);

		mIcon.setClickable(true);
		mIcon.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				ViewUserInfo();
			}
		});
		mName.setClickable(true);
		mName.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				ViewUserInfo();
			}
		});
       
//		footView = (LinearLayout) LayoutInflater.from(this).inflate(
//				R.layout.list_header, null);
		mHeaderMore = (TextView) findViewById(R.id.header_all);
		mHeaderMore.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.e(" pyb ", " mHeaderMore was click here ");
				url_all_comments = "/api/statuses/comments/" + mId
						+ ".json?api_key=";
				mIsLargeTen = true;
				new AsyncDataLoader(asyncRemoteCallback, mctx,
						url_all_comments, "", "", "").execute();
			}
		});

		mbtnBack = (Button) findViewById(R.id.btn_title_back);
		mbtnBack.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.e(TAG, " back button was click......");
				// Intent intent = new
				// Intent(WeiboDetailsActivity.this,MainTabs.class);
				// startActivity(intent);
				finish(); // finish the WeiboDetailsActivity
			}
		});

		mbtnReply = (Button) findViewById(R.id.btn_title_reply);
		mbtnReply.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.e(TAG, " Reply button was click......mApp_type = "
						+ mApp_type);
				Log.e(TAG,
						" Reply button was click......Pw_type = "
								+ mDetails.getPw_type());
				if (null != mDetails.getApp_info()) {
					if (mApp_type.equals(ConfigInfo.COMM.APP_TYPE_TASK)) { // task
						Log.e(" pyb ", " mAppTypeStatus task ========  ");
						if (null != mDetails.getApp_info()
								&& mDetails
										.getApp_info()
										.getRsvp()
										.equals(ConfigInfo.COMM.APP_TASK_UNDONE)
								|| mDetails.getApp_info().getRsvp()
										.equals(ConfigInfo.COMM.APP_TASK_INIT)) {
							showDialog(TASK_UNDONE);
						} else {
							showDialog(TASK_DONE);
						}
					} else if (mApp_type
							.equals(ConfigInfo.COMM.APP_TYPE_MEETING)) { // meeting
						Log.e(" pyb ",
								" mAppTypeStatus meeting ========  rsvp = "
										+ mDetails.getApp_info().getRsvp());
						if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_MEETING_INIT)) {
							showDialog(MEETING_INIT);
						} else if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_MEETING_JOIN)) {
							showDialog(MEETING_JOIN);
						} else if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_MEETING_UNJOIN)) {
							showDialog(MEETING_UNJOIN);
						} else {
							showDialog(MEETING_UNKNOW);
						}
					} else if (mApp_type.equals(ConfigInfo.COMM.APP_TYPE_EVENT)) { // event
						Log.e(" pyb ",
								" mAppTypeStatus event ========  rsvp = "
										+ mDetails.getApp_info().getRsvp());
						if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_EVENT_INIT)) {
							showDialog(EVENT_INIT);
						} else if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_EVENT_JOIN)) {
							showDialog(EVENT_JOIN);
						} else if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_EVENT_UNJOIN)) {
							showDialog(EVENT_UNJOIN);
						} else {
							showDialog(EVENT_UNKNOW);
						}
					} else if (mApp_type
							.equals(ConfigInfo.COMM.APP_TYPE_APPROVE)) { // approve

						Log.e(" pyb ",
								" mAppTypeStatus approve ========  rsvp = "
										+ mDetails.getApp_info().getRsvp());
						if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_APPROVE_INIT)) {
							showDialog(APPROVE_INIT);
						} else {
							showDialog(APPROVE_FINAL);
						}
					}
				} else {
					// from the "Activity" to this WeiboDetailsActivity
					// Intent i = new
					// Intent(WeiboDetailsActivity.this,CreateWeiBoActivity.class);
					// i.putExtra(ConfigInfo.COMM.SEND_TYPE,ConfigInfo.COMM.WEIBO_MSG_REPLY);
					// i.putExtra(ConfigInfo.COMM.DETAIL_ID,mDetails.getId());
					// startActivityForResult(i, REPLY_WEIBO);
					// ReplyMsg();
					if (mDetails.getPw_type().equals(
							ConfigInfo.COMM.PW_TYPE_REPLY)) { // 表示回复的消息
						showDialog(MSG_REPLY);
					} else {
						showDialog(REPLY_BTN);
					}
				}
			}
		});

		mShowHtml = (ImageView) findViewById(R.id.details_view_show_html);
		mShowHtml.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.e(TAG, " WeiboDetailsActivity mShowHtml was click Url = "
						+ mDetails.getContent().getHtml());
				// startActivity(new Intent(Intent.ACTION_VIEW,
				// Uri.parse(mDetails.getContent().getHtml())));

				Intent i = new Intent(WeiboDetailsActivity.this,
						WebViewActivity.class);
				i.putExtra(ConfigInfo.COMM.HTML, mDetails.getContent()
						.getHtml());
				startActivity(i);
			}
		});
		mContent = (TextView) findViewById(R.id.details_view_content);
		mLinkContent = (TextView) findViewById(R.id.details_view_link_content);
		mLinkContent.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.e(TAG,
						" WeiboDetailsActivity mLinkContent was click, url = "
								+ mDetails.getContent().getUrl());
				startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(mDetails
						.getContent().getUrl())));
			}
		});

		mPicContent = (ImageView) findViewById(R.id.details_view_pic_content);
		mPicContent.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.e(TAG,
						" WeiboDetailsActivity mPicContent was click ,Thumbnail = "
								+ mDetails.getContent().getUrl());
				Intent i = new Intent(WeiboDetailsActivity.this,
						PicActivity.class);
				i.putExtra(ConfigInfo.COMM.USER_ID, mDetails.getId());
				i.putExtra(ConfigInfo.COMM.THUMBNAIL, mDetails.getContent()
						.getUrl());
				startActivity(i);
			}
		});
		mDivider = (View) findViewById(R.id.details_view_divider);
		mDetailsList = (LinearLayoutForListView) findViewById(R.id.weibo_details_list);
		mDetailsList.setOnclickLinstener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int position =  Integer.parseInt(v.getTag().toString());
				Log.e(TAG," mDetailsList setOnclickLinstener() called ... position = " + position);
				if (position < mArrayComments.length) {
					Intent intent = new Intent(WeiboDetailsActivity.this,
							WeiboDetailsActivity.class);
					intent.putExtra(ConfigInfo.COMM.MSG_ID,
							mArrayComments[position].getId());
					intent.putExtra(ConfigInfo.COMM.ROOT_ID,
							WeiboDetailsActivity.this.mRootId);
					// intent.putExtra(ConfigInfo.COMM.APP_TYPE,
					// list.get(position).getApp_type());
					intent.putExtra(ConfigInfo.COMM.ITEM_TYPE, "");
					startActivity(intent);
				}
			}
		});
//		mDetailsList.setOnItemClickListener(new OnItemClickListener() {
//
//			@Override
//			public void onItemClick(AdapterView<?> parent, View view,
//					int position, long id) {
//				// TODO Auto-generated method stub
//				Log.e(TAG,
//						" mDetailsList setOnItemClickListener() called ... position = "
//								+ position);
//
//				Log.e(TAG,
//						" | mDetailsList setOnItemClickListener() called ... position = "
//								+ position);
//				if (position < mArrayComments.length) {
//					Intent intent = new Intent(WeiboDetailsActivity.this,
//							WeiboDetailsActivity.class);
//					intent.putExtra(ConfigInfo.COMM.MSG_ID,
//							mArrayComments[position].getId());
//					intent.putExtra(ConfigInfo.COMM.ROOT_ID,
//							WeiboDetailsActivity.this.mRootId);
//					// intent.putExtra(ConfigInfo.COMM.APP_TYPE,
//					// list.get(position).getApp_type());
//					intent.putExtra(ConfigInfo.COMM.ITEM_TYPE, "");
//					startActivity(intent);
//				}
//			}
//		});

		mIntent = getIntent();
		mId = mIntent.getStringExtra(ConfigInfo.COMM.MSG_ID);
		mNofity_id = mIntent.getStringExtra(ConfigInfo.COMM.NOTIFY_ID);
		mRootId = mIntent.getStringExtra(ConfigInfo.COMM.ROOT_ID);
		mApp_type = mIntent.getStringExtra(ConfigInfo.COMM.APP_TYPE);
		mItemType = mIntent.getStringExtra(ConfigInfo.COMM.ITEM_TYPE);
		url_show_id = "/api/statuses/show/" + mId + ".json?api_key=";
		url_show_root_id = "/api/statuses/show/" + mRootId + ".json?api_key=";
		Log.e(TAG, " WeiboDetailsActivity onCreate() called, mId =  " + mId
				+ " , mRootId = " + mRootId + " ,mNofity_id = " + mNofity_id);
		new AsyncDataLoader(asyncRemoteCallback, this, url_show_id, "", "", "")
				.execute();
//		mDetailsList.addFooterView(footView);

		///pyb ======
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		String str = data.getStringExtra(ConfigInfo.COMM.SEND_TYPE);
		Log.e(TAG,
				" onActivityResult() called ... ==================================  str =  "
						+ str);
		if (ConfigInfo.CALLBACK_CREATE_WEIBO == requestCode) {
			if (str.equals(ConfigInfo.COMM.WEIBO_MSG_REPLY)) {
				if (mItemType.equals("letter")) {
					// the private letter should hide the comment list
					// 私信不用显示回复列表以及回复数量
					Log.e(TAG,
							" the private letter should hide the comment list =====================   ");
					return;
				}
				// update the WeiboDetails View UI,maybe there was some comment
				// happend
				new AsyncDataLoader(asyncRemoteCallback, this, url_show_id, "",
						"", "").execute();
				ConfigInfo.COMM.UPDATE_DATA = true;
			}
		} else if (requestCode == ConfigInfo.CALLBACK_REPLY_WEIBO) {
			Log.e(TAG,
					" onActivityResult() called ... requestCode == ConfigInfo.CALLBACK_REPLY_WEIBO  ");
			// update the WeiboDetails View UI,maybe there was some comment
			// happend
			if (mFlag) {
				new AsyncDataLoader(asyncRemoteCallback, this,
						url_show_root_id, "", "", "").execute();
				mFlag = false;
			} else {
				new AsyncDataLoader(asyncRemoteCallback, this, url_show_id, "",
						"", "").execute();
			}

			ConfigInfo.COMM.UPDATE_DATA = true;
		}
	}

	private void ViewUserInfo() {
		if (mName.getText().toString().trim() != "") {
			Intent intent = new Intent(WeiboDetailsActivity.this,
					UserInfoActivity.class);
			intent.putExtra(ConfigInfo.COMM.USER_NAME, mName.getText()
					.toString().trim());
			startActivity(intent);
		}
	}

	private void ViewRootMsg() {
		Log.e(TAG, "in function ViewRootMsg() ：rootid=" + this.mRootId);
		Intent intent = new Intent(WeiboDetailsActivity.this,
				WeiboDetailsActivity.class);
		intent.putExtra(ConfigInfo.COMM.MSG_ID, this.mRootId);
		// intent.putExtra(ConfigInfo.COMM.ROOT_ID,
		// list.get(position).getRoot_id());
		// intent.putExtra(ConfigInfo.COMM.APP_TYPE,
		// list.get(position).getApp_type());
		intent.putExtra(ConfigInfo.COMM.ITEM_TYPE, "");
		startActivity(intent);
	}

	private void ReplyMsg() {
		// if(null == mDetails ){
		// mDetailsList.setFocusable(false);
		// Log.e(TAG,
		// " no data   in the ReplyMsg() function=====================================  ");
		// return;
		// }
		// from the "Activity" to this WeiboDetailsActivity
		Intent i = new Intent(WeiboDetailsActivity.this,
				CreateWeiBoActivity.class);
		if (mItemType.equals("letter")) {
			i.putExtra(ConfigInfo.COMM.SEND_TYPE,
					ConfigInfo.COMM.WEIBO_LETTER_REPLY);
			i.putExtra(ConfigInfo.COMM.DETAIL_ID, mDetails.getId());
			startActivityForResult(i, ConfigInfo.CALLBACK_REPLY_LETTER);
			Log.e(TAG,
					"ReplyMsg() function,reply to the private letter here=  ");
		} else {
			i.putExtra(ConfigInfo.COMM.SEND_TYPE,
					ConfigInfo.COMM.WEIBO_MSG_REPLY);
			i.putExtra(ConfigInfo.COMM.DETAIL_ID, mDetails.getId());
			startActivityForResult(i, ConfigInfo.CALLBACK_REPLY_WEIBO);
			Log.e(TAG,
					"ReplyMsg() function,reply to the weibo msg here *****************  ");
		}
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Log.e(TAG, " WeiboDetailsActivity onStart() called...");
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		Log.e(TAG, " WeiboDetailsActivity onResume() called....");
//		new Utility().setListViewHeightBasedOnChildren(mDetailsList);
		mFlag = false;
		// if(!mApp_type.equals("")){ // task,event,meeting or approve
		// //show some controls in the view
		// if(mApp_type.equals(ConfigInfo.COMM.APP_TYPE_TASK)){ //task
		// mAppTypeTimeTitle.setVisibility(View.VISIBLE);
		// mAppTypeTimeTitle.setText(mctx.getString(R.string.app_type_deadline));
		// }
		// }
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		Log.e(TAG,
				" WeiboDetailsActivity onDestroy() called =====================================================...");
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case 0:// task undone
			return new AlertDialog.Builder(WeiboDetailsActivity.this)
					.setTitle(mctx.getString(R.string.task_title))
					.setItems(R.array.select_task_items_undone,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									Log.e(" pyb ", " 00000  which = " + which); // undone
									switch (which) {
									case 0:
										// reply to others
										ReplyMsg();
										break;
									case 1:
										String url_modify_appstate = "/api/statuses/modify_appstate/"
												+ mId + ".json?api_key=";
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_TASK,
												"1", "").execute();
										break;
									case 2:
										// cancle
										break;
									default:
										break;
									}
								}
							}).create();
		case 1:// task done
			return new AlertDialog.Builder(WeiboDetailsActivity.this)
					.setTitle(mctx.getString(R.string.task_title))
					.setItems(R.array.select_task_items_done,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {// done
									Log.e(" pyb ", " 1111  which = " + which);
									switch (which) {
									case 0:
										// reply to others
										ReplyMsg();
										break;
									case 1:
										String url_modify_appstate = "/api/statuses/modify_appstate/"
												+ mId + ".json?api_key=";
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_TASK,
												"2", "").execute();
										break;
									case 2:
										break;
									default:
										break;
									}
								}
							}).create();
		case 2: // meeting init
			return new AlertDialog.Builder(WeiboDetailsActivity.this)
					.setTitle(mctx.getString(R.string.app_type_meeting))
					.setItems(R.array.select_meeting_event_items_init,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {// done
									Log.e(" pyb ", " 1111  which = " + which);
									String url_modify_appstate = "/api/statuses/modify_appstate/"
											+ mId + ".json?api_key=";
									switch (which) {
									case 0:
										// reply to others
										ReplyMsg();
										break;
									case 1:// join
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_MEETING,
												ConfigInfo.COMM.APP_MEETING_JOIN,
												"").execute();
										break;
									case 2:// unjoin
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_MEETING,
												ConfigInfo.COMM.APP_MEETING_UNJOIN,
												"").execute();
										break;
									case 3:// unknow
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_MEETING,
												ConfigInfo.COMM.APP_MEETING_UNKNOW,
												"").execute();
										break;
									default:
										break;
									}
								}
							}).create();
		case 3: // meeting join
			return new AlertDialog.Builder(WeiboDetailsActivity.this)
					.setTitle(mctx.getString(R.string.app_type_meeting))
					.setItems(R.array.select_meeting_event_items_join,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {// join
									String url_modify_appstate = "/api/statuses/modify_appstate/"
											+ mId + ".json?api_key=";
									Log.e(" pyb ", " meeting join  which = "
											+ which);
									switch (which) {
									case 0:
										// reply to others
										ReplyMsg();
										break;
									case 1:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_MEETING,
												ConfigInfo.COMM.APP_MEETING_UNJOIN,
												"").execute();
										break;
									case 2:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_MEETING,
												ConfigInfo.COMM.APP_MEETING_UNKNOW,
												"").execute();
										break;
									default:
										break;
									}
								}
							}).create();
		case 4: // meeting un join
			return new AlertDialog.Builder(WeiboDetailsActivity.this)
					.setTitle(mctx.getString(R.string.app_type_meeting))
					.setItems(R.array.select_meeting_event_items_unjoin,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {// join
									String url_modify_appstate = "/api/statuses/modify_appstate/"
											+ mId + ".json?api_key=";
									Log.e(" pyb ", " meeting join  which = "
											+ which);
									switch (which) {
									case 0:
										// reply to others
										ReplyMsg();
										break;
									case 1:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_MEETING,
												ConfigInfo.COMM.APP_MEETING_JOIN,
												"").execute();
										break;
									case 2:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_MEETING,
												ConfigInfo.COMM.APP_MEETING_UNKNOW,
												"").execute();
										break;
									case 3:
										break;
									default:
										break;
									}
								}
							}).create();
		case 5: // meeting un know
			return new AlertDialog.Builder(WeiboDetailsActivity.this)
					.setTitle(mctx.getString(R.string.app_type_meeting))
					.setItems(R.array.select_meeting_event_items_unknow,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {// join
									String url_modify_appstate = "/api/statuses/modify_appstate/"
											+ mId + ".json?api_key=";
									Log.e(" pyb ", " meeting un know  which = "
											+ which);
									switch (which) {
									case 0:
										// reply to others
										ReplyMsg();
										break;
									case 1:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_MEETING,
												ConfigInfo.COMM.APP_MEETING_JOIN,
												"").execute();
										break;
									case 2:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_MEETING,
												ConfigInfo.COMM.APP_MEETING_UNJOIN,
												"").execute();
										break;
									case 3:
										break;
									default:
										break;
									}
								}
							}).create();
		case 6: // event init
			return new AlertDialog.Builder(WeiboDetailsActivity.this)
					.setTitle(mctx.getString(R.string.app_type_event))
					.setItems(R.array.select_meeting_event_items_init,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {// join
									String url_modify_appstate = "/api/statuses/modify_appstate/"
											+ mId + ".json?api_key=";
									Log.e(" pyb ", " event un know  which = "
											+ which);
									switch (which) {
									case 0:
										// reply to others
										ReplyMsg();
										break;
									case 1:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_EVENT,
												ConfigInfo.COMM.APP_EVENT_JOIN,
												"").execute();
										break;
									case 2:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_EVENT,
												ConfigInfo.COMM.APP_EVENT_UNJOIN,
												"").execute();
										break;
									case 3:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_EVENT,
												ConfigInfo.COMM.APP_EVENT_UNKNOW,
												"").execute();
										break;
									default:
										break;
									}
								}
							}).create();
		case 7:// event join
			return new AlertDialog.Builder(WeiboDetailsActivity.this)
					.setTitle(mctx.getString(R.string.app_type_event))
					.setItems(R.array.select_meeting_event_items_join,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {// join
									String url_modify_appstate = "/api/statuses/modify_appstate/"
											+ mId + ".json?api_key=";
									Log.e(" pyb ", " event un know  which = "
											+ which);
									switch (which) {
									case 0:
										// reply to others
										ReplyMsg();
										break;
									case 1:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_EVENT,
												ConfigInfo.COMM.APP_EVENT_UNJOIN,
												"").execute();
										break;
									case 2:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_EVENT,
												ConfigInfo.COMM.APP_EVENT_UNKNOW,
												"").execute();
										break;
									case 3:
										break;
									default:
										break;
									}
								}
							}).create();
		case 8:// event unjoin
			return new AlertDialog.Builder(WeiboDetailsActivity.this)
					.setTitle(mctx.getString(R.string.app_type_event))
					.setItems(R.array.select_meeting_event_items_unjoin,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {// join
									String url_modify_appstate = "/api/statuses/modify_appstate/"
											+ mId + ".json?api_key=";
									Log.e(" pyb ", " event un know  which = "
											+ which);
									switch (which) {
									case 0:
										// reply to others
										ReplyMsg();
										break;
									case 1:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_EVENT,
												ConfigInfo.COMM.APP_EVENT_JOIN,
												"").execute();
										break;
									case 2:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_EVENT,
												ConfigInfo.COMM.APP_EVENT_UNKNOW,
												"").execute();
										break;
									case 3:
										break;
									default:
										break;
									}
								}
							}).create();
		case 9:// event un know
			return new AlertDialog.Builder(WeiboDetailsActivity.this)
					.setTitle(mctx.getString(R.string.app_type_event))
					.setItems(R.array.select_meeting_event_items_unknow,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {// join
									String url_modify_appstate = "/api/statuses/modify_appstate/"
											+ mId + ".json?api_key=";
									Log.e(" pyb ", " event un know  which = "
											+ which);
									switch (which) {
									case 0:
										// reply to others
										ReplyMsg();
										break;
									case 1:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_EVENT,
												ConfigInfo.COMM.APP_EVENT_JOIN,
												"").execute();
										break;
									case 2:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_EVENT,
												ConfigInfo.COMM.APP_EVENT_UNJOIN,
												"").execute();
										break;
									case 3:
										break;
									default:
										break;
									}
								}
							}).create();
		case 10: // approve init
			return new AlertDialog.Builder(WeiboDetailsActivity.this)
					.setTitle(mctx.getString(R.string.app_type_approve))
					.setItems(R.array.select_approve_items_init,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {// join
									String url_modify_appstate = "/api/statuses/modify_appstate/"
											+ mId + ".json?api_key=";
									Log.e(" pyb ", " approve init  which = "
											+ which);
									switch (which) {
									case 0:
										// reply to others
										ReplyMsg();
										break;
									case 1:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_APPROVE,
												ConfigInfo.COMM.APP_APPROVE_PASS,
												"").execute();
										break;
									case 2:
										new AsyncDataLoader(
												ModifyStateCallback,
												mctx,
												url_modify_appstate,
												ConfigInfo.COMM.APP_TYPE_PARA_APPROVE,
												ConfigInfo.COMM.APP_APPROVE_UNPASS,
												"").execute();
										break;
									case 3:
										break;
									default:
										break;
									}
								}
							}).create();
		case 11:// approve final,pass or un pass
			return new AlertDialog.Builder(WeiboDetailsActivity.this)
					.setTitle(mctx.getString(R.string.app_type_approve))
					.setItems(R.array.select_approve_items_final,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {// join
									String url_modify_appstate = "/api/statuses/modify_appstate/"
											+ mId + ".json?api_key=";
									Log.e(" pyb ", " approve final  which = "
											+ which);
									switch (which) {
									case 0:
										// reply to others
										ReplyMsg();
										break;
									case 1:
										// cancle
										break;
									default:
										break;
									}
								}
							}).create();
		case 12:
			return new AlertDialog.Builder(WeiboDetailsActivity.this).setItems(
					R.array.select_approve_items_final,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {// join
						// Log.e(" pyb ", " approve final  which = " + which);
							switch (which) {
							case 0:
								// reply to others
								ReplyMsg();
								break;
							case 1:
								// cancle
								break;
							default:
								break;
							}
						}
					}).create();
		case 13:
			return new AlertDialog.Builder(WeiboDetailsActivity.this).setItems(
					R.array.msg_reply_type_items,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {// join
							switch (which) {
							case 0:
								// mDetailsList.setFocusable(true);
								// review the original msg
								// mFlag = true;
								// new
								// AsyncDataLoader(asyncRemoteCallback,mctx,url_show_root_id,"","","").execute();
								ViewRootMsg();
								break;
							case 1:
								// reply
								ReplyMsg();
								break;
							case 2:
								// cancle
							default:
								break;
							}
						}
					}).create();
		default:
			break;
		}
		return null;
	}

	/**
	 * 异步加载服务器上的微博数据的监听器
	 */
	private AsyncDataLoader.Callback asyncRemoteCallback = new AsyncDataLoader.Callback() {

		private SharedPreferences mPrefs;
		private String result;

		@Override
		public void onStart(String address, String id) {
			mPrefs = getSharedPreferences(ConfigInfo.USER_PREFERENCES,
					MODE_PRIVATE);
			StringBuffer url = new StringBuffer();
			url.append(mPrefs.getString(ConfigInfo.PREF_SERVER_ADDRESS, mPrefs
					.getString(ConfigInfo.PREF_SERVER_ADDRESS,
							ConfigInfo.COMM.CONST_SERVER_ADDRESS)));
			url.append(address);
			url.append(ConfigInfo.COMM.APY_KEY);
			// unread msg was read here
			if (null != mNofity_id) {
				url.append("&notify_id=");
				url.append(mNofity_id);
				// unread tab button UI should update here
				// ConfigInfo.IS_UN_READ_VIEW = true; //no need update data from
				// the server,just remove data here
				Log.e(TAG,
						" mNofity_id != null  mNofity_id != null   mNofity_id != null   mNofity_id != null");
			}
			if (mIsLargeTen) {
				url.append("&id=");
				url.append(mId);
			}
			String username = mPrefs.getString(ConfigInfo.PREF_USERNAME, "");
			String passwd = mPrefs.getString(ConfigInfo.PREF_PASSWORD, "");

			// 需要做出判断，username 或者 passwd为非法值

			result = HttpUtils.doPost(url.toString(), username, passwd,null);
			Log.e(TAG, "--------------------------------------url address = "
					+ url);
			// Log.e(""," username  = "+username);
			// Log.e(""," passwd  = "+passwd);
			Log.e(TAG, " weibo details show id  result =  " + result);
			if (result != ConfigInfo.HTTPRETURN.COMMHTTPERRORS
					&& result != ConfigInfo.HTTPRETURN.HTTP_ERROR_400
					&& result != ConfigInfo.HTTPRETURN.HTTP_ERROR_401
					&& result != ConfigInfo.HTTPRETURN.HTTP_ERROR_CODE_404
					&& result != ConfigInfo.HTTPRETURN.HTTPERROR) {
				try {
					if (mIsLargeTen) {
						mCommentsList = JsonUtils.parseUserFromJsons(result,
								listType);
						Log.e(TAG,
								" weibo details show id  mCommentsList size =  "
										+ mCommentsList.size());
						mArrayAllComments = new Comments[mCommentsList.size()];
						for (int i = 0; i < mCommentsList.size(); i++) {
							mArrayAllComments[i] = mCommentsList.get(i);
						}
						mArrayComments = mArrayAllComments;
						handler.post(new Runnable() {
							@Override
							public void run() {
//								mDetailsList.removeAllViews();
//								mHeaderMore.setVisibility(View.GONE);
							}
						});
						Log.e(TAG, "//////////all comments count:"
								+ mArrayAllComments.length);
					} else {
						mDetails = JsonUtils.parseUserFromJson(result,
								Details.class);
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} else if (result == ConfigInfo.HTTPRETURN.HTTP_ERROR_CODE_404) {
				Log.i(TAG, "//////////// 404");
				handler.post(new Runnable() {
					@Override
					public void run() {
						Toast.makeText(WeiboDetailsActivity.this,
								ConfigInfo.HTTPRETURN.HTTP_ERROR_MSG_DEL,
								Toast.LENGTH_LONG).show();
					}
				});
			} else {
				// get no data from the server
				handler.post(new Runnable() {
					@Override
					public void run() {
						Toast.makeText(WeiboDetailsActivity.this,result,Toast.LENGTH_LONG).show();
					}
				});
			}
		}

		@Override
		public void onStart(String address, String arg1, String arg2) {
			// TODO Auto-generated method stub
			// do nothing here
		}

		@Override
		public void onPrepare() {
		}

		@Override
		public void onFinish() {
			String created_time = null;
			if (null == mDetails.getContent()) { // get no data error.
				mDetailsList.setFocusable(false);
				// mbtnReply.setEnabled(false);
				mbtnReply.setVisibility(View.GONE);
				return;
			}
			if (mIsLargeTen) {
				DetailsItemAdapter adapter = new DetailsItemAdapter(
						mArrayAllComments, WeiboDetailsActivity.this);
				mDetailsList.setAdapter(adapter);
				//pyb =====
//				mDetailsList.removeFooterView(footView);
				//已经显示 了所有的 回复信息，因此将其 隐藏起来
				mHeaderMore.setVisibility(View.GONE);
				mIsLargeTen = false;
//				new Utility().setListViewHeightBasedOnChildren(mDetailsList);
				return;
			}
			String content_type = mDetails.getContent().getType();
			if (content_type.equals(ConfigInfo.COMM.CONTENT_TYPE_LINK)
					|| content_type.equals(ConfigInfo.COMM.CONTENT_TYPE_VEDIO)) { // link
																					// 0
																					// ,vedio
																					// 3,
			// mShowHtml.setVisibility(View.VISIBLE);
				mLinkContent.setVisibility(View.VISIBLE);
				String linkTitle = "";
				if (mDetails.getContent().getUploadfile().equals("1")
						&& null != mDetails.getContent().getTitle()
						&& !mDetails.getContent().getTitle().equals("")) {
					linkTitle = mDetails.getContent().getTitle();
				} else {
					linkTitle = (content_type
							.equals(ConfigInfo.COMM.CONTENT_TYPE_VEDIO) ? mctx
							.getString(R.string.video_url) : "")
							+ mDetails.getContent().getUrl();
				}

				mLinkContent.setText(linkTitle);
			}
			if (content_type.equals(ConfigInfo.COMM.CONTENT_TYPE_RICH_HTML)
					|| content_type
							.equals(ConfigInfo.COMM.CONTENT_TYPE_RICH_EMBEDDED)
					|| content_type
							.equals(ConfigInfo.COMM.CONTENT_TYPE_RICH_FORM)) { // rich_text,
																				// 10,11,12
				mShowHtml.setVisibility(View.VISIBLE);
				/*ViewGroup.LayoutParams par = mAppTypeStatus.getLayoutParams();
				par.height += 60;
				mAppTypeStatus.setLayoutParams(par);*/
				
				RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(90, 30);
				params.leftMargin = 145;
				mAppTypeStatus.setLayoutParams(params);
				params = new RelativeLayout.LayoutParams(50, 30);
				params.leftMargin = 105;
				mAppTypeContent.setLayoutParams(params);				
				
			}
			if (content_type.equals(ConfigInfo.COMM.CONTENT_TYPE_PIC)) { // pciture,
																			// 2
				mPicContent.setVisibility(View.VISIBLE);
				asyncImageLoader.loadPortrait(mDetails.getContent().getUrl(), mPicContent);
			}
			mArrayComments = mDetails.getComments();
			int count = Integer.parseInt(mDetails.getComments_count());
			if (count > 10) {
				mHeaderMore.setVisibility(View.VISIBLE);
				mHeaderMore.setText(mctx.getString(R.string.header_all_1)
						+ mDetails.getComments_count()
						+ mctx.getString(R.string.header_all_2));
				Log.e(TAG, " all comments num is count =  " + count);
			}else{
				mHeaderMore.setVisibility(View.GONE);
			}
			mName.setText(mDetails.getUser().getUsername());
			try {
				created_time = java.net.URLEncoder.encode(
						mDetails.getCreated_time(), "utf-8");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

			mRootId = mDetails.getRoot_id();
			mApp_type = mDetails.getApp_type();
			// mItemType = mDetails.getPw_type();
			mCreateTime.setText(TimeUtil.convertToLocalTime(mDetails.getCreated_time()));
			Log.e(TAG, "  getComments_count = " + mDetails.getComments_count()
					+ ",created_time = " + created_time);
			mCnt.setVisibility(View.VISIBLE);
			mCnt.setText(mDetails.getComments_count());
			mCommentTitle.setVisibility(View.VISIBLE);
			mContent.setText(mDetails.getContent().getText());
			asyncImageLoader.loadPortrait(mDetails.getUser().getProfile_picture(), mIcon);
			mApp_type = mDetails.getApp_type();
			Log.e(TAG, " mApp_type = " + mApp_type);
			if (!mApp_type.equals("")) { // task,event,meeting or approve
				// show some controls in the view
				if (mApp_type.equals(ConfigInfo.COMM.APP_TYPE_TASK)
						&& null != mDetails.getApp_info()) { // task
					mAppTypeTimeTitle.setVisibility(View.VISIBLE);
					mAppTypeTime.setVisibility(View.VISIBLE);

					mAppTypeContent.setVisibility(View.VISIBLE);
					mAppTypeStatus.setVisibility(View.VISIBLE);
					Log.e("", " task status Rsvp = "
							+ mDetails.getApp_info().getRsvp());
					mAppTypeContent.setText(mctx
							.getString(R.string.app_type_task));
					if (mDetails.getApp_info().getRsvp()
							.equals(ConfigInfo.COMM.APP_TASK_DONE)) {// done
						mAppTypeStatus.setText(mctx
								.getString(R.string.task_status_done));
					} else if (mDetails.getApp_info().getRsvp()
							.equals(ConfigInfo.COMM.APP_TASK_UNDONE)
							|| mDetails.getApp_info().getRsvp()
									.equals(ConfigInfo.COMM.APP_TASK_INIT)) {// undone
																				// or
																				// init
						mAppTypeStatus.setText(mctx
								.getString(R.string.task_status_undone));
					} else {

					}
					// hide the comment and the count
					// mCommentTitle.setVisibility(View.GONE);
					// mCnt.setVisibility(View.GONE);

					mAppTypeTimeTitle.setText(mctx.getString(R.string.app_type_deadline));
					Log.e("", " task end time1 = " + mDetails.getApp_info().getEnd_date());
					if(mDetails.getApp_info().getEnd_date().equals("0000-00-00 00:00:00") 
							|| mDetails.getApp_info().getEnd_date().equals("")){
						mAppTypeTime.setText(mctx.getString(R.string.app_type_no_time));
					}else{
						mAppTypeTime.setText(TimeUtil.convertToLocalTime(mDetails.getApp_info().getEnd_date()));
					}
					//mAppTypeTime.setText("abc");
				} else if (mApp_type.equals(ConfigInfo.COMM.APP_TYPE_MEETING)
						&& null != mDetails.getApp_info()) { // meeting
					mAppTypeTimeTitle.setVisibility(View.VISIBLE);
					mAppTypeTime.setVisibility(View.VISIBLE);

					mAppTypeContent.setVisibility(View.VISIBLE);
					mAppTypeStatus.setVisibility(View.VISIBLE);

					mAppTypeContent.setText(mctx
							.getString(R.string.app_type_meeting));
					//mAppTypeTime.setText(mDetails.getApp_info().getStart_date());
					mAppTypeTime.setText(TimeUtil.convertToLocalTime(mDetails.getApp_info().getStart_date()));
					if (mDetails.getApp_info().getRsvp()
							.equals(ConfigInfo.COMM.APP_MEETING_INIT)) {
						mAppTypeStatus.setText("");
					} else if (mDetails.getApp_info().getRsvp()
							.equals(ConfigInfo.COMM.APP_MEETING_JOIN)) { // join
																			// the
																			// meeting
						mAppTypeStatus
								.setText(": "
										+ mctx.getString(R.string.app_type_meeting_join));
					} else if (mDetails.getApp_info().getRsvp()
							.equals(ConfigInfo.COMM.APP_MEETING_UNJOIN)) {
						mAppTypeStatus
								.setText(": "
										+ mctx.getString(R.string.app_type_meeting_unjoin));
					} else if (mDetails.getApp_info().getRsvp()
							.equals(ConfigInfo.COMM.APP_MEETING_UNKNOW)) {
						mAppTypeStatus
								.setText(": "
										+ mctx.getString(R.string.app_type_meeting_unknow));
					} else {
						// do nothing in the meeting
					}
				} else if (mApp_type.equals(ConfigInfo.COMM.APP_TYPE_EVENT)
						&& null != mDetails.getApp_info()) { // event
					mAppTypeTimeTitle.setVisibility(View.VISIBLE);
					mAppTypeTime.setVisibility(View.VISIBLE);

					mAppTypeContent.setVisibility(View.VISIBLE);
					mAppTypeStatus.setVisibility(View.VISIBLE);

					mAppTypeContent.setText(mctx
							.getString(R.string.app_type_event));
					//mAppTypeTime.setText(mDetails.getApp_info().getStart_date());
					mAppTypeTime.setText(TimeUtil.convertToLocalTime(mDetails.getApp_info().getStart_date()));
					if (mDetails.getApp_info().getRsvp()
							.equals(ConfigInfo.COMM.APP_EVENT_INIT)) {
						mAppTypeStatus.setText("");
					} else if (mDetails.getApp_info().getRsvp()
							.equals(ConfigInfo.COMM.APP_EVENT_JOIN)) { // join
																		// the
																		// event
						mAppTypeStatus.setText(": "
								+ mctx.getString(R.string.app_type_event_join));
					} else if (mDetails.getApp_info().getRsvp()
							.equals(ConfigInfo.COMM.APP_EVENT_UNJOIN)) {
						mAppTypeStatus
								.setText(": "
										+ mctx.getString(R.string.app_type_event_unjoin));
					} else if (mDetails.getApp_info().getRsvp()
							.equals(ConfigInfo.COMM.APP_EVENT_UNKNOW)) {
						mAppTypeStatus
								.setText(": "
										+ mctx.getString(R.string.app_type_event_unknow));
					} else {
						// do nothing in the event
					}
					// end of the event
				} else if (mApp_type.equals(ConfigInfo.COMM.APP_TYPE_APPROVE)) { // approve
					mAppTypeTimeTitle.setVisibility(View.INVISIBLE);
					mAppTypeTime.setVisibility(View.INVISIBLE);

					mAppTypeContent.setVisibility(View.VISIBLE);
					mAppTypeStatus.setVisibility(View.VISIBLE);

					mAppTypeContent.setText(mctx
							.getString(R.string.app_type_approve));
					if (mDetails.getApp_info().getRsvp()
							.equals(ConfigInfo.COMM.APP_APPROVE_INIT)) {
						mAppTypeStatus.setText(": "
								+ mctx.getString(R.string.approve_status_wait));
					} else if (mDetails.getApp_info().getRsvp()
							.equals(ConfigInfo.COMM.APP_APPROVE_PASS)) { // pass
																			// the
																			// approve
						mAppTypeStatus.setText(": "
								+ mctx.getString(R.string.approve_status_pass));
					} else if (mDetails.getApp_info().getRsvp()
							.equals(ConfigInfo.COMM.APP_APPROVE_UNPASS)) { // un
																			// pass
																			// the
																			// approve
						mAppTypeStatus
								.setText(": "
										+ mctx.getString(R.string.approve_status_unpass));
					} else {
						// do nothing in the approve
					}
				}// end of the approve
			}// end of the !mApp_type.equals(""
			if (mItemType.equals("letter")) { // hide the comment
				mCommentTitle.setVisibility(View.GONE);
				mCnt.setVisibility(View.GONE);
				// the private letter should hide the comment list
				// 私信不用显示回复列表以及回复数量
				mDetailsList.setVisibility(View.INVISIBLE);
			}
			DetailsItemAdapter adapter = new DetailsItemAdapter(mArrayComments,
					WeiboDetailsActivity.this);
			mDetailsList.setAdapter(adapter);
//			new Utility().setListViewHeightBasedOnChildren(mDetailsList);
			Log.e(TAG, " getPw_type = " + mDetails.getPw_type());
			if (mDetails.getPw_type().equals(ConfigInfo.COMM.PW_TYPE_REPLY)) { // 表示回复的内容，
																				// 显示图标
				mReplyType.setVisibility(View.VISIBLE);
				// 表示回复的内容,隐藏回复title和回复数量
				mCommentTitle.setVisibility(View.GONE);
				mCnt.setVisibility(View.GONE);
			} else {
				mReplyType.setVisibility(View.GONE);
			}
			mDivider.setVisibility(View.VISIBLE);
		}

	};

	/**
	 * 异步修改app_info的状态，并且在UI上显示修改后的状态
	 */
	private AsyncDataLoader.Callback ModifyStateCallback = new AsyncDataLoader.Callback() {
		private SharedPreferences mPrefs;
		private String mResult;

		@Override
		public void onStart(String address, String id) {
			// TODO Auto-generated method stub
			// do nothing here ,pyb
		}

		@Override
		public void onFinish() {
			// TODO Auto-generated method stub
			if (!mResult.equals("")) {
				if (!mApp_type.equals("")) {
					if (mApp_type.equals(ConfigInfo.COMM.APP_TYPE_TASK)) { // task
						if (mDetails.getApp_info().getRsvp().equals("1")) {
							mAppTypeStatus.setText(mctx
									.getString(R.string.task_status_done));
						} else {
							mAppTypeStatus.setText(mctx
									.getString(R.string.task_status_undone));
						}
					} else if (mApp_type
							.equals(ConfigInfo.COMM.APP_TYPE_MEETING)) { // meeting
						if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_MEETING_JOIN)) { // join
							mAppTypeStatus
									.setText(": "
											+ mctx.getString(R.string.app_type_meeting_join));
						} else if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_MEETING_UNJOIN)) {
							mAppTypeStatus
									.setText(": "
											+ mctx.getString(R.string.app_type_meeting_unjoin));
						} else if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_MEETING_UNKNOW)) {
							mAppTypeStatus
									.setText(": "
											+ mctx.getString(R.string.app_type_meeting_unknow));
						} else {

						}
					} else if (mApp_type.equals(ConfigInfo.COMM.APP_TYPE_EVENT)) { // event
						if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_EVENT_JOIN)) { // join
							mAppTypeStatus
									.setText(": "
											+ mctx.getString(R.string.app_type_event_join));
						} else if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_EVENT_UNJOIN)) {
							mAppTypeStatus
									.setText(": "
											+ mctx.getString(R.string.app_type_event_unjoin));
						} else if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_EVENT_UNKNOW)) {
							mAppTypeStatus
									.setText(": "
											+ mctx.getString(R.string.app_type_event_unknow));
						} else {

						}
					} else if (mApp_type
							.equals(ConfigInfo.COMM.APP_TYPE_APPROVE)) { // approve
						if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_APPROVE_PASS)) { // approve
																				// pass
							mAppTypeStatus
									.setText(": "
											+ mctx.getString(R.string.approve_status_pass));
						} else if (mDetails.getApp_info().getRsvp()
								.equals(ConfigInfo.COMM.APP_APPROVE_UNPASS)) {// approve
																				// un
																				// pass
							mAppTypeStatus
									.setText(": "
											+ mctx.getString(R.string.approve_status_unpass));
						} else {

						}
					}

				}
			}
		}

		@Override
		public void onPrepare() {
			// TODO Auto-generated method stub

		}

		@Override
		public void onStart(String address, String arg1, String arg2) {
			// TODO Auto-generated method stub
			mPrefs = getSharedPreferences(ConfigInfo.USER_PREFERENCES,
					MODE_PRIVATE);
			StringBuffer url = new StringBuffer();
			url.append(mPrefs.getString(ConfigInfo.PREF_SERVER_ADDRESS, mPrefs
					.getString(ConfigInfo.PREF_SERVER_ADDRESS,
							ConfigInfo.COMM.CONST_SERVER_ADDRESS)));
			url.append(address);
			url.append(ConfigInfo.COMM.APY_KEY);
			url.append("&type=" + arg1);
			url.append("&state=" + arg2);

			// modify the value of the status,task,event,meeting,approve
			mDetails.getApp_info().setRsvp(arg2);

			Log.e("", " modify app_type url address = " + url);
			String username = mPrefs.getString(ConfigInfo.PREF_USERNAME, "");
			String passwd = mPrefs.getString(ConfigInfo.PREF_PASSWORD, "");

			// 需要做出判断，username 或者 passwd为非法值

			mResult = HttpUtils.doPost(url.toString(), username, passwd, null);
			Log.e("", " modify task result = " + mResult);
		}
	};
}
